<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增帖子')" />
	<th:block th:include="include :: select2-css" />
	<th:block th:include="include :: datetimepicker-css" />

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-post-add">
			<div class="form-group">	
				<label class="col-sm-2 control-label">话题名称：</label>
				<div class="col-sm-8">
					<!--<input id="topicId" name="topicId" class="form-control" type="text">-->
					<select id="topicId" name="topicId" class="form-control m-b">
						<option></option>
						<option th:each="topic:${topicList}"
								th:value="${topic.id}"
								th:text="${topic.topicName}"></option>
					</select>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">用户ID：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="userId" name="userId" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">审核状态：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="verifyState" name="verifyState" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">	
				<label class="col-sm-2 control-label">帖子类型：</label>
				<div class="col-sm-3">
					<select id="postType" name="postType" class="form-control m-b">
						<option value=1>参与话题</option>
						<option value=2>不参与话题</option>
					</select>
				</div>

			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">点赞量：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="likeNum" name="likeNum" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">浏览量：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="glanceNum" name="glanceNum" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">评论量：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="commentsNum" name="commentsNum" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">是否被举报  1是2否：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="isComplain" name="isComplain" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->

				<label class="col-sm-2 control-label">公开级别：</label>
				<div class="col-sm-3">
					<select id="openLevel" name="openLevel" class="form-control m-b">
						<option value=3>所有人可见</option>
						<option value=2>关注可见</option>
						<option value=1>仅自己可见</option>
					</select>
				</div>
			</div>
			<!--<div class="form-group">-->
				<!--<label class="col-sm-2 control-label">帖子等级：</label>-->
				<!--<div class="col-sm-3">-->
					<!--<input id="postLevel" name="postLevel" class="form-control" type="number">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">发帖地址：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="postAddress" name="postAddress" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">经度：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="addressLong" name="addressLong" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">纬度：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="addressLati" name="addressLati" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">	
				<label class="col-sm-2 control-label">帖子内容：</label>
				<div class="col-sm-8">
					<textarea id="postContent" name="postContent" class="form-control" type="text"></textarea>
				</div>
			</div>
			<div class="form-group" style="">
				<label class="col-sm-2 control-label">帖子图片：</label>
				<div class="col-sm-8">
					<input id="postImg" name="postImg" class="form-control" type="hidden">
					<img id="imageUrlSrc" width="100px" height="100px" src="http://qnbangbang.laigl.com/1d38c06a-2f3c-4eda-b8a4-f3a15e557441" onclick="avator()"/>
				</div>
			</div>
			<div class="form-group">
				<div id="preview" style="display: none;">
					<p>
						上传文件：
						<input id="file" name="file" type="file" onchange="load(this)" multiple="multiple" accept="image/*" class='myfile'></input>


					</p>
				</div>
			</div>

			<div class="form-group" id="test" style="margin-left: 200px"></div>








			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">有效值：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="valid" name="valid" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">建立日期：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="createDate" name="createDate" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">修改日期：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="modifyDate" name="modifyDate" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
		</form>
	</div>
    <div th:include="include::footer"></div>
	<th:block th:include="include :: select2-js" />
	<th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
		var prefix = ctx + "post/post";
		var srcString = new Array();
		$("#form-post-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});

		function avator() {
			$("#file").click();
		}
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-post-add').serialize());
	        }
	    }


		$('body').on('click','.close',function(){
			$(this).parent('.imgbox').remove();
		});

		function load(file) {
			var num=1;
			var length= 9 ;
			if (file.files.length < 9) {
				length = file.files.length;
			}
			if (file.files) {

				for (var i = 0; i < length; i++) {
					var reader = new FileReader();
					reader.readAsDataURL(file.files[i]);
					reader.onload = function(evt) {
						// var imgbox=$('<div></div>');
						// imgbox.addClass('imgbox');
						// $('#view').append(imgbox);
						//
						// var close=$('<div>&times;</div>');
						// close.addClass('close');
						// close.appendTo(imgbox);
						//
						// var imgs = $('<input type="image" />');
						// imgs.attr('name','mum'+num);
						// num++;
						// imgs.appendTo(imgbox);
						// imgs.attr('src', evt.target.result);
						var src = evt.target.result;
						srcString.push(src);
						// alert(srcString);
						html = '<div>'+ '<a class="col-sm-4">'+
								'<img style="width: 200px; height: 200px;" class="control-label" id="img'+i+'"  src="'+src+'" />'+ '</a>'+
								'</div>';
						$('#test').append(html);
						console.log(srcString);
						if(i=length-1){
							//$("input[name='postImg']").val(srcString.join(','));
							$("input[name='postImg']").val(srcString.join(','));
						} else if (i==0) {
							$("input[name='postImg']").val(srcString.join(','));
						}
					}
				}
			}
		}
	</script>
</body>
</html>
